import { ref } from "vue";
import { defineStore } from "pinia";

// 定义store
export const useMemberStore = defineStore('member',
  () => {
    //会员信息
    const profile = ref();

    // 保存会员信息，登录时使用
    const setProfile = (val: any) => {
      profile.value = val
    }

    // 群里会员信息，退出时使用
    const clearProfile = () => {
      profile.value = undefined
    }

    return {
      profile,
      setProfile,
      clearProfile,
    }
  },
  // 持久化
  {
    // H5端
    // persist: true,
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      }
    }
  }
)